﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using XMK.Tadong.Model;
using XMK.Tadong.Biz;
using HU8.Helpers.Base;
using System.Web.SessionState;

namespace XMK.Tadong.Web.WebFileExplorer.WebServices
{
    /// <summary>
    /// ShareFile 的摘要说明
    /// 共享模快处理程序
    /// </summary>
    public class ShareFile : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //通过用户id获得课题组id列表
        //    string userId = context.Request.Cookies["_userId_"].Value;// context.Request.Params["id"].ToString();
            string userId = context.Session["user_id"].ToString();
            Tb_Team_UserBiz team_userBiz = new Tb_Team_UserBiz();
            //DataTable dt = team_userBiz.GetTeamListByUserId(userId);
            List<Base_UserSpaceInfo> spaces = team_userBiz.GetSpaceListByUserId(userId);
            //通过课题组id获得课题组信息
            DataTable teamdt = new DataTable();
            teamdt.Columns.Add("TEAM_ID", typeof(System.String));
            teamdt.Columns.Add("TEAM_NAME", typeof(System.String));
            for (int i = 0; i < spaces.Count; i++)
            {
                //decimal teamid = (decimal)dt.Rows[i]["TEAM_ID"];
                //Tb_TeamBiz tb_teamBiz = new Tb_TeamBiz();
                //TB_TEAMInfo team = tb_teamBiz.GetTeamInfoById(teamid);
                //if (spaces[i].IsOpen && spaces[i].SpaceName != "项目库空间")
                if (spaces[i].IsOpen)
                {
                    DataRow row = teamdt.NewRow();
                    row["TEAM_ID"] = spaces[i].SpaceId;
                    row["TEAM_NAME"] = spaces[i].SpaceName;
                    teamdt.Rows.Add(row);
                }
               
            }
            teamdt.TableName = "table";

            teamdt.Columns[0].ColumnName = "TEAM_ID";
            teamdt.Columns[1].ColumnName = "TEAM_NAME";
            DataSet ds = new DataSet();
            ds.DataSetName = "tables";
            ds.Tables.Add(teamdt);
            context.Response.ContentType = "application/xml";
            string result = JsonHelper.ToJson(teamdt);
            context.Response.Write(result);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}